package interview.eventSystem;

/**
 * Created by richard on 6/3/14.
 */
public class Client implements Runnable {//implement runnable for simulate


    private int clientId=0;

    private Container container;

    public Client(int clientId) {
        this.clientId = clientId;
    }

    public Container getContainer() {
        return container;
    }

    public void setContainer(Container container) {
        this.container = container;
    }

    public void consumeEvent(Event event){
        System.out.println("consume a event in client:" + clientId + "with eventId " + event.getId() + " : " + event.getMessage());
    }

    @Override
    public void run() {
        try {
        while(!Thread.currentThread().isInterrupted()) {

            Thread.sleep(1000);
            consumeEvent(getContainer().getEvent());
        }

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
